window.onload = function () {



    document.onkeydown = function(event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "keyboard" : {
                "type" : "onkeydown",
                "code" : e.code ,
                "keyCode" : e.keyCode
            }

        }
        websocketsend(JSON.stringify(data))

    };

    document.onkeyup = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "keyboard" : {
                "type" : "onkeyup",
                "code" : e.code ,
                "keyCode" : e.keyCode
            }

        }
        websocketsend(JSON.stringify(data));
    };

    document.onmousedown = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "onmousedown",
                "button" : e.button
            }

        }
        websocketsend(JSON.stringify(data))

    };
    document.onmouseup = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "onmouseup",
                "button" : e.button
            }

        }
        websocketsend(JSON.stringify(data));

    };
    document.onmousemove = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        let clientWidth = window.innerWidth ;
        let clientHeight = window.innerHeight;


        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "onmousemove",
                "movementX" : (e.clientX/clientWidth)*1920,
                "movementY" : (e.clientY/clientHeight)*1080
            }

        }
        websocketsend(JSON.stringify(data));

    };

    document.onmousewheel = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        let clientWidth = window.innerWidth ;
        let clientHeight = window.innerHeight;
        let screenWeight = screen.width;
        let screenHeight = screen.height;

        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "wheelDelta",
                "wheelDeltaX" : (e.wheelDeltaX/clientWidth)*screenWeight,
                "wheelDeltaY" : (e.wheelDeltaY/clientHeight)*screenHeight
            }

        }
        websocketsend(JSON.stringify(data));

    };

    document.onclick = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "onclick",
                "button" : e.button
            }

        }
        websocketsend(JSON.stringify(data));

    };

    document.ondblclick = function(event) {
        const e = event || window.event || arguments.callee.caller.arguments[0];
        e.preventDefault(); //阻止默认事件
        // 设置获取的值
        let data = {
            "mouse" : {
                "type" : "ondblclick",
                "button" : e.button
            }

        }
        websocketsend(JSON.stringify(data));

    };


}